import { createRouter, createWebHashHistory } from "vue-router";
import Index from "../views/Index/Index.vue";
import Login from "../views/Index/Login.vue";
import Reg from "../views/Index/Reg.vue";
import GoodsIndex from "../views/Goods/Index.vue";
import GoodsLists from "../views/Goods/Lists.vue";
import GoodsDetails from "../views/Goods/Details.vue";
import CartIndex from "../views/Cart/Index.vue";
import CartOrder from "../views/Cart/Order.vue";
import CartPay from "../views/Cart/Pay.vue";
import MyIndex from "../views/My/Index.vue";
import MyOrder from "../views/My/Order.vue";
import MyOrderDetails from "../views/My/OrderDetails.vue";
import MyAddress from "../views/My/MyAddress.vue";

const routes = [
  {
    path: "/",
    alias: "/index",
    name: "Index",
    component: Index,
    meta: {
      title: "首页",
    }
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "登录",
    }
  },
  {
    path: "/reg",
    name: "Reg",
    component: Reg,
    meta: {
      title: "注册",
    }
  },
  {
    path: "/goods_index",
    name: "GoodsIndex",
    component: GoodsIndex,
    meta: {
      title: "分类",
    }
  },
  {
    path: "/goods_lists",
    name: "GoodsLists",
    component: GoodsLists,
    meta: {
      title: "列表",
    }
  },
  {
    path: "/goods_details",
    name: "GoodsDetails",
    component: GoodsDetails,
    meta: {
      title: "详情",
    }
  },
  {
    path: "/cart_index",
    name: "CartIndex",
    component: CartIndex,
    meta: {
      title: "购物车",
    }
  },
  {
    path: "/cart_order",
    name: "CartOrder",
    component: CartOrder,
    meta: {
      title: "下单",
    }
  },
  {
    path: "/cart_pay",
    name: "CartPay",
    component: CartPay,
    meta: {
      title: "支付",
    }
  },
  {
    path: "/my_index",
    name: "MyIndex",
    component: MyIndex,
    meta: {
      title: "个人中心",
    }
  },
  {
    path: "/my_order",
    name: "MyOrder",
    component: MyOrder,
    meta: {
      title: "订单列表",
    }
  },
  {
    path: "/my_order_details",
    name: "MyOrderDetails",
    component: MyOrderDetails,
    meta: {
      title: "订单详情",
    }
  },
  {
    path: "/my_address",
    name: "MyAddress",
    component: MyAddress,
    meta: {
      title: "我的地址",
    }
  }
];

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to) => {
  document.title = to.meta.title;
});

export default router;
